var exec = require("child_process").exec;

function convert(file_name, new_type) {
  console.log('Converting file ' + file_name + ' to ' + new_type);
  
  var converted_file = '/tmp/' + file_name + new Date().getTime() + '.' + new_type;
  var cmd = 'java -jar lib/jodconverter-cli-2.2.2.jar ~/anexos/' + file_name + ' ' + converted_file;
  
  console.log('Executing command: ' + cmd);
  try {
    exec(cmd);
  } catch (err) {
    console.log(err.stack);
    converted_file = undefined;
  }
  
  return converted_file;
}

exports.convert = convert;
